package com.jy.wms.controller;

import com.alibaba.fastjson.JSONArray;
import com.jy.wms.common.base.BaseController;
import com.jy.wms.pojo.SysDictionary;
import com.jy.wms.service.SysDictionaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: SysDictionaryController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author liyi
 * @Date Fri Sep 01 13:47:12 CST 2017
 */
@Controller
@RequestMapping("/sysdictionary")
@Api(value = "/sysdictionary", description = "关于字典管理实体类")
public class SysDictionaryController extends BaseController<SysDictionaryService,SysDictionary> {

    @GetMapping(value = "/getSysdictionary/{type}")
    @ApiOperation(value = "字典管理 获取字典属性",response = JSONObject.class, notes = "GET根据类型查看字典属性")
    public @ResponseBody JSONArray getSysdictionary(@PathVariable("type") String type) {
        JSONArray jsonArray = new JSONArray();
        try {
            List<SysDictionary> list = baseService.baseSelectByType(type);
            for (int i = 0; i < list.size(); i++) {
                SysDictionary sysDictionary =  list.get(i);
                JSONObject json = new JSONObject();
                json.put("dictionaryid",sysDictionary.getD_value());
                json.put("value",sysDictionary.getD_name());
                jsonArray.add(json);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonArray;
    }

  @GetMapping(value = "/getSysZkdictionary/{type}")
    @ApiOperation(value = "字典管理 获取字典属性(子库获取用户类型)",response = JSONObject.class, notes = "GET根据类型查看子库获取类型字典属性")
    public @ResponseBody JSONArray getSysZkdictionary(@PathVariable("type") String type) {
        JSONArray jsonArray = new JSONArray();
        try {
            List<SysDictionary> listzk = baseService.baseSelectByZkType(type);
            for (int i = 0; i < listzk.size(); i++) {
                SysDictionary sysDictionaryZk =  listzk.get(i);
                JSONObject json = new JSONObject();
                json.put("dictionaryid",sysDictionaryZk.getD_value());
                json.put("value",sysDictionaryZk.getD_name());
                jsonArray.add(json);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonArray;
    }
}
